/*
 *Copyright (c) [2019] [name of copyright holder]
 *[Software Name] is licensed under the Mulan PSL v1.
 *You can use this software according to the terms and conditions of the Mulan PSL v1.
 *You may obtain a copy of Mulan PSL v1 at:
 *http://license.coscl.org.cn/MulanPSL
 *THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
 *IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
 *PURPOSE.
 *See the Mulan PSL v1 for more details.
 */

/*!
 * \autor captainpeng
 * \date 2019-12-27
 * \version 1.0
 */

#ifndef MY_QUEUE_HPP
#define MY_QUEUE_HPP

#include"mystd.hpp"

namespace my{

    template<typename T>
    class queue{
    public:
        using buffType = buffer<T>;
        using elementType = typename buffType::elementType;

    private:
        buffType mBuf;
        int mHead;
        int mTail;
        
    public:
        queue(int len = 0x100):
            mBuf(len),
            mHead(-1),
            mTail(-1)
        {}

        inline int size(){
            if(mHead >= mTail)
                return mHead - mTail;
            else
                return mBuf.size() - mTail + mHead;
        }

        inline int capacity(){
            return mBuf.size();
        }

        inline bool empty(){
            return mHead == -1;
        }

    };
}

#endif
